import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'

const Layout = () => import('@/views/Layout.vue')
const Home = () => import('@/views/home/index.vue')
const TopCategory = () => import('@/views/category/index.vue')
const SubCategory = () => import('@/views/category/sub.vue')
const Goods = () => import('@/views/goods/index.vue')
const routes: RouteRecordRaw[] = [
  // 一级路由
  {
    path: '/',
    component: Layout,
    children: [
      { path: '/', component: Home },
      { path: '/category/:id', component: TopCategory },
      { path: '/category/sub/:id', component: SubCategory },
      { path: '/product/:id', component: Goods },
    ]
  }
]
export default createRouter({
  // 指定路由模式
  history: createWebHashHistory(),
  // 路由地址
  routes,
  // 每次切换路由时滚动到最顶部
  scrollBehavior() {
    return { left: 0, top: 0 }
  }
})